<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<%@ include file="/commons/head.jsp" %>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="/commons/left.jsp" %>
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                角色列表
            </h1>
            <section class="content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                                <div class="input_box col-sm-5 margin">
                                    <form name="searchForm" id="searchForm"
                                          action="${ctx}/problem/listProblem" method="get">
                                        <input type="hidden" id="pageNum" name="pageNum" value="1"/>
                                        <input type="hidden" id="length" name="length" value="10"/>
                                    </form>
                                </div>
                                <div class="margin" style="float:right;">
                                    <button type="button" class="btn btn-default"
                                            onclick="window.location.href='${ctx}/role/editRole?action=add'"><span
                                            class="glyphicon glyphicon-plus"></span> 新增
                                    </button>
                                </div>
                            </div>
                            <div class="box-body">
                                <table id="example2" class="table table-bordered table-hover">
                                    <thead>
                                    <tr>
                                        <th>角色主键</th>
                                        <th>角色名称</th>
                                        <th>角色代码</th>
                                        <th>备注</th>
                                        <th>创建者</th>
                                        <th class="time">创建时间</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <c:if test="${page.maxRow > 0}">
                                        <c:forEach var="item" items="${listRole}" varStatus="vs">
                                            <tr>
                                                <td>${item.id}</td>
                                                <td>${item.roleName}</td>
                                                <td>${item.roleCode}</td>
                                                <td>${item.remark}</td>
                                                <td>${item.operator}</td>
                                                <td>
                                                    <fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss"
                                                                    value="${item.createTime}"/>
                                                </td>
                                                <c:if test="${item.disable==1}">
                                                    <td><span class="red">禁用</span></td>
                                                    <td><a onclick="able('${item.id}',0)"
                                                           data-able="1">启用</a><em> </em><a
                                                            onclick="window.location.href='${ctx}/role/editRole?action=update&id=${item.id}'">修改</a>
                                                    </td>
                                                </c:if>
                                                <c:if test="${item.disable==0}">
                                                    <td><span class="green">启用</span></td>
                                                    <td><a onclick="able('${item.id}',1)"
                                                           data-able="0">禁用</a><em> </em><a
                                                            onclick="window.location.href='${ctx}/role/editRole?action=update&id=${item.id}'">修改</a>
                                                    </td>
                                                </c:if>
                                            </tr>
                                        </c:forEach>
                                    </c:if>
                                    </tbody>
                                </table>
                                <div>
                                    <jsp:include page="/commons/pagination.jsp"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </section>

    </div>
    <%@ include file="/commons/script.jsp" %>
    <script type="text/javascript">
        function able(id, obj) {
            $.ajax({
                cache: false,
                type: "post",
                url: '${ctx}/role/updateRoleIsAble',
                data: {
                    id: id,
                    disable: obj
                },
                success: function (data) {
                    if (data == 1) {
                        //成功处理
                        if (obj == 0) {
                            alert("禁用成功");
                        } else {
                            alert("启用成功");
                        }
                    }
                    location.reload();
                },
                error: function () {
                    alert("系统异常");
                }
            });
        }
    </script>
</body>
</html>